#define _CRT_SECURE_NO_WARNINGS 1


#include<iostream>

using namespace std;

int main()
{
	long long n = 0;
	cin >> n;
	long long Max = 0;
	for (int i = 1; i < n; i++)
	{
		long long temp = i;
		while (temp != 1)
		{
			if (temp % 2 == 0)
			{
				temp /= 2;
			}
			else
			{
				temp = temp * 3 + 1;
			}
			Max = max(Max, temp);
		}
	}
	cout << Max << endl;

	return 0;
}